package com.xxx.listener;

import com.xxx.event.DemoEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * ②事件监听器：接收事件并处理（基于注解，多个listener可以监听同一个事件）
 */
@Slf4j
@Component
public class DemoEvent2Listener {

    // @EventListener(value = {DemoEvent.class, DemoEvent.class})
    @EventListener(value = {DemoEvent.class, DemoEvent.class}, condition = "#demoEvent.msg.length() == 'my-event'")   // 带过滤条件
    public void onApplicationEvent(DemoEvent demoEvent) {
        String msg = demoEvent.getMsg();
        log.info("listener 收到了 publisher 发布的消息: " + msg);
    }
}
